<template>
    <!-- 分包商分子公司汇总新增 -->
    <div class="e-form">
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <div style="width: 100%" class="form">
                <el-form :model="formData" label-width="150px">
                    <BillTop
                        title="分包商分子公司汇总新增"
                        @cancel="handleClose"
                    ></BillTop>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="汇总日期：">
                                <el-date-picker
                                    v-model="formData.collectDate"
                                    type="date"
                                    placeholder="选择日期"
                                    :clearable="false"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>

                        <el-col :span="12">
                            <el-form-item label="汇总时间区：">
                                {{ formData.summartDate }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="评价机构："
                                >{{ formData.evaluateOrg }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="状态：">
                                {{ formData.state }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-form-item label="备注："
                            ><el-input
                                type="textarea"
                                :rows="2"
                                placeholder="请输入内容"
                                v-model="formData.remark"
                            >
                            </el-input
                        ></el-form-item>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="经办人："
                                >{{ formData.evaluateOrg }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="最后修改时间：">
                                {{ formData.state }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                style="background: #2e61d7"
                @click="save()"
                >保存</el-button
            >
            <el-button @click="cancel()">取消</el-button>
        </div>
        <span style="display: none">{{ localPopConfirm }}</span>
    </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import { mapMutations, mapState } from 'vuex'
import { showSuccessPop } from '@/utils/common'
export default {
    data () {
        return {
            //表单数据
            formData: {
                collectDate: new Date()
                    .toLocaleDateString()
                    .replaceAll('/', '-'), //汇总日期
                summartDate: '', //汇总时间区
                evaluateOrg: '', //评价机构
                state: '草稿', //状态
                superiorsOrg: '', //上级机构
                remark: '' //备注
            },

            orgId: '', //机构id
            orgName: '', //机构名称
            isSkip: false //是否跳转
        }
    },
    computed: {
        ...mapState({
            options: state => state.contract.ctClassify,
            popConfirm: 'popConfirm',
            popStatus: 'popStatus'
        }),
        localPopConfirm () {
            if (this.popConfirm) {
                switch (this.popStatus) {
                case 'prompt':
                    this.delData()
                    break
                case 'success':
                    if (this.isSkip) this.handleClose()
                    break
                }
                this.setPopConfirm(false)
            }
            return this.popConfirm
        }
    },
    components: {},
    created () {
        let data = JSON.parse(localStorage.getItem('vuex'))
        this.orgId = data.userInfo.orgInfo.orgId
        this.orgName = data.userInfo.orgInfo.orgName
    },
    mounted () {},
    beforeDestroy () {},
    methods: {
        ...mapMutations(['setPopConfirm']),
        //保存按钮
        save () {
            // //日期转换格式
            let collectDate = this.getTime(this.formData.collectDate)
            this.$Ajax
                .httpPost({
                    url: '/outer/summary/create',
                    params: {
                        billDate: collectDate, //	单据时间
                        billNo: '', //	评价编号
                        closeDate: '', //	截止评价日期
                        evaluateYear: '', //	评价年度
                        gmtCreate: '', //	录入时间
                        gmtModified: '', //最后修改时间
                        groupDtlList: [], //集团汇总明细
                        id: '', //评价ID
                        isGroup: 0, //	是否是集团汇总(是集团传1 是分子公司传0)
                        orgId: this.orgId, //	创建机构ID
                        orgName: this.orgName, //	机构名称
                        releasestate: 0, //	发布状态0未发布1发布
                        remark: '', //	备注
                        state: 0, //状态
                        subDtlList: [], //分子公司汇总明细
                        summartDate: '2008-01-01——2022-01-01', //	汇总时间区间
                        workId: '' //作业ID
                    }
                })
                .then(() => {
                    showSuccessPop('保存成功！')
                    this.isSkip = false
                })
        },
        //提交按钮
        submit () {
            // //日期转换格式
            let collectDate = this.getTime(this.formData.collectDate)
            this.$Ajax
                .httpPost({
                    url: '/outer/summary/create',
                    params: {
                        billDate: collectDate, //	单据时间
                        billNo: '', //	评价编号
                        closeDate: '', //	截止评价日期
                        evaluateYear: '', //	评价年度
                        gmtCreate: '', //	录入时间
                        gmtModified: '', //最后修改时间
                        groupDtlList: [], //集团汇总明细
                        id: '', //评价ID
                        isGroup: 0, //	是否是集团汇总(是集团传1 是分子公司传0)
                        orgId: this.orgId, //	创建机构ID
                        orgName: this.orgName, //	机构名称
                        releasestate: 0, //	发布状态0未发布1发布
                        remark: '', //	备注
                        state: 0, //状态
                        subDtlList: [], //分子公司汇总明细
                        summartDate: '2008-01-01——2022-01-01', //	汇总时间区间
                        workId: '' //作业ID
                    }
                })
                .then(() => {
                    showSuccessPop('保存成功！')
                    this.isSkip = false
                    this.$router.push('/collectEvaluate')
                })
        },

        //取消按钮
        cancel () {
            this.$router.push('/collectEvaluate')
        },
        //日期转换格式
        getTime (dt) {
            var year = dt.getFullYear() //年
            var month = dt.getMonth() + 1 //月
            var date = dt.getDate() //日
            month = month < 10 ? '0' + month : month
            date = date < 10 ? '0' + date : date
            var str = year + '-' + month + '-' + date
            return str
        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    margin-bottom: 80px;
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}

.form {
}

.e-table {
    background: #fff;
}

.el-tab-pane {
    margin-left: -10px;
}
</style>
